package com.fancy.learncenter.net;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.widget.ScrollView;


import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.utils.LogUtil;
import com.fancy.learncenter.utils.ProgressUtil;
import com.fancy.learncenter.utils.ToastUtil;

import okhttp3.ResponseBody;
import retrofit2.Response;
import rx.Subscriber;

/**
 * Created by Hyy on 2016/12/16.
 */

public abstract class CustomNetSubscriber extends Subscriber<Response<ResponseBody>> {
    Dialog dialog = null;
    Activity context;

    private boolean isDialogShow;

    public CustomNetSubscriber(Activity context) {
        this.context = context;
        isDialogShow = true;
    }

    public CustomNetSubscriber(Activity context, boolean isDialogShow) {
        this.context = context;

        this.isDialogShow = isDialogShow;
    }


    @Override
    public void onCompleted() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    @Override
    public void onError(Throwable e) {
//        ToastUtil.show(Constant.NET_ERROR);
        if (dialog != null) {
            dialog.dismiss();
        }

        LogUtil.MyLog("responseBodyResponse", "======onError=======" + e);
    }

    @Override
    public void onStart() {
        super.onStart();

        if (isDialogShow) {
            if (dialog == null) {
                dialog = ProgressUtil.creatRequestDialog(context, "正在发送电波");
            }
            dialog.show();
        }
    }

    public Activity getContext() {
        return context;
    }
}
